package cn.whuc.sparksql

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.sql.{DataFrame, Dataset, SparkSession}

object Demo_UDAF {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf().setAppName("sql").setMaster("local[*]")
    val ss: SparkSession = SparkSession.builder().config(conf).getOrCreate()

    import ss.implicits._

    val df: DataFrame = ss.read.json("input/user.json")

    df.createTempView("user")

    ss.udf.register("f1",(n:String)=>{
      "姓名："+n
    })

    ss.udf.register("f2",(a:Int)=>{
      a+10
    })

    ss.sql("select f1(username),f2(age) from user").show()


    ss.stop()
  }
}


